package com.common.entity;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class R<T> {

    private Boolean isSuccess;

    private Integer code;

    private T data;

    private String msg;


    public static <T> R<T> ok() {
        return new R<T>(Renum.OK.getSuccess(), Renum.OK.getCode(), null, Renum.OK.getMessage());
    }

    public static <T> R<T> ok(T data) {
        return new R<T>(Renum.OK.getSuccess(), Renum.OK.getCode(), data, Renum.OK.getMessage());
    }

    public static <T> R<T> ok(String msg) {
        return new R<T>(Renum.OK.getSuccess(), Renum.OK.getCode(), null, msg);
    }

    public static <T> R<T> ok(T data, String msg) {
        return new R<T>(Renum.OK.getSuccess(), Renum.OK.getCode(), data, msg);
    }

    public static <T> R<T> fail() {
        return new R<T>(Renum.Fail.getSuccess(), Renum.Fail.getCode(), null, Renum.Fail.getMessage());
    }

    public static <T> R<T> fail(String msg) {
        return new R<T>(Renum.Fail.getSuccess(), Renum.Fail.getCode(), null, msg);
    }

}
